package com.heitian.ssm.controller;

import com.google.gson.JsonObject;
import com.heitian.ssm.dao.FeedBackDao;
import com.heitian.ssm.model.FeedBack;
import com.heitian.ssm.service.FeedBackService;
import com.heitian.ssm.utils.CommonUtils;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 作者： 陈建峰
 * 创建时间： 18/3/28 下午11:27
 * 版本： [1.0, 18/3/28]
 * 描述： <描述>
 */
@Controller
@RequestMapping("/feedback")
public class FeedBackController {

    @Resource
    FeedBackService feedBackService;

    @RequestMapping(value = "/SaveFeedBack", method = RequestMethod.POST)
    public void SaveFeedBack(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
        response.setHeader("Content-type", "text/html;charset=UTF-8");
        JsonObject paras = CommonUtils.getJson(request);
        if (paras == null) {
            response.getWriter().write(CommonUtils.createJson("0", "", null).toString());
            return;
        }
        String UserGuid = paras.get("UserGuid").getAsString();
        String Content = paras.get("Content").getAsString();
        String DisplayName = paras.get("DisplayName").getAsString();
        FeedBack feedBack = new FeedBack();
        feedBack.setContent(Content);
        feedBack.setUserGuid(UserGuid);
        feedBack.setDisplayName(DisplayName);
        feedBack.setUpdataTime(CommonUtils.getCurrentTime());
        feedBackService.SaveFeedBack(feedBack);
        response.getWriter().write(CommonUtils.createJson("1", "添加成功！", null).toString());
    }
}
